import { defHttp } from '@/utils/http';

enum Api {
  getList = '/v1/system/rule',
  save = '/v1/system/rule',
  del = '/v1/system/rule',
  upStatus = '/v1/system/rule/state',
  getAll = '/v1/system/rule/all',
  UpdateInfo = '/v1/system/rule',
}

//获取数据
export function getList(params: object) {
  return defHttp.get(
    { url: Api.getList, params: params },
    { errorMessageMode: 'none' }
  );
}

//新增
export function add(params: object) {
  return defHttp.post(
    { url: Api.save, params: params },
    { errorMessageMode: 'message' }
  );
}

//修改
export function update(params: object) {
  return defHttp.put(
    { url: Api.UpdateInfo, params: params },
    { errorMessageMode: 'message' }
  );
}

//删除数据
export function del(params: object) {
  return defHttp.delete(
    { url: Api.del, params: params },
    { errorMessageMode: 'message' }
  );
}

//更新状态
export function upStatus(params: object) {
  return defHttp.put(
    { url: Api.upStatus, params: params },
    { errorMessageMode: 'message' }
  );
}

//获取全部数据
export function getAllRule(params: object) {
  return defHttp.get(
    { url: Api.getAll, params: params },
    { errorMessageMode: 'message' }
  );
}

/**数据类型 */
export interface DataTreeItemRule {
  id?: number;
  locale?: string;
  children?: DataTreeItemRule[]; // 子节点
  title?: string;
}
